﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.OleDb;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class login : System.Web.UI.Page
{
    public OleDbConnection myConnection;
    public static readonly string sConnectionString = System.Configuration.ConfigurationManager.AppSettings["SQLConnString"].ToString();
    protected void Page_Load(object sender, EventArgs e)
    {
        myConnection = new OleDbConnection(sConnectionString);
        myConnection.Open();
        if (!IsPostBack)
        {
            RadioButtonStu.Checked = true;//首次打开页面，默认选择“学生”
           
            Session["UserNo"] = null;//保质期
            Session["UserName"] = null;
        }

    }
   
    protected void ButtonOK_Click(object sender, EventArgs e)
    {
            if (RadioButtonStu.Checked)//选择学生用户登录
            {
                string mysql = "select * from StudentTb where sNo='" + UserNo.Text.Trim() + "'and sPass='" + UserPass.Text.Trim() + "'  ";//查询学号和密码是否正确
                OleDbCommand mycmd = new OleDbCommand(mysql, myConnection);
                OleDbDataReader myReader = mycmd.ExecuteReader();
                if (myReader.Read())
                {
                    Session["UserNo"] = UserNo.Text.Trim();//保存学号
                    Session["UserName"] = myReader[2].ToString();//保存姓名
                    Response.Redirect("student/studentMenu.aspx");//跳转到学生页面
                }
                else
                    LabelError.Text = "*您输入学号或密码有误，请重新输入！";
            }
            
            else//选择管理员用户登录
            {
                string mysql = "select * from ManagerTb where nNo='" + UserNo.Text.Trim() + "'and nPass='" + UserPass.Text.Trim() + "'  ";
                OleDbCommand mycmd = new OleDbCommand(mysql, myConnection);
                OleDbDataReader myReader = mycmd.ExecuteReader();
                if (myReader.Read())
                {
                    Session["UserNo"] = UserNo.Text.Trim();//保存学号
                    Session["UserName"] = myReader[2].ToString();//保存姓名
                    Response.Redirect("adminstrator/adminMenu.aspx");//跳转到管理员页面
                }
                else
                    LabelError.Text = "*您输入工号或密码有误，请重新输入！";
            }
        }
    }





